var router = module.exports = require('express').Router();
var Datastore = require('nedb');
var db = new Datastore({
    filename:'./api/friends/friends.data',
    autoload: true
});
// ds.loadDatabase();
router.route('/friends')
    .get(function(req, res) {
        db.find({}, function(err, docs) {
            res.json(docs);
        });
    })
    .post(function(req, res) {
        console.log(req.body);
        db.find({}, function(err, docs) {
            res.json(docs);
        });
        // res.json({id: Date.now()});
    });

router.route('/friends/:id')
    .get(function(req, res) {
        // console.log(req.params.id);
        var id = req.params.id;
        db.findOne({ id: Number(id)}, function(err, doc) {
            res.json(doc);
        });
    })
    .post(function(req, res) {
        // console.log(req.params.id);
        var id = req.params.id;
        db.findOne({ id: Number(id)}, function(err, doc) {
            res.json(doc);
        });
    })
    .put(function(req, res) {
        res.json({id: Date.now()});
    })
    .delete(function(req, res) {
        res.json({id: Date.now()});
    });
